The Java Tutorial Books

The Java Tutorial | About the Java Tutorial Books > The Java Tutorial Second Edition Errata book | TOC | CD-ROM | References | Errata |

- Fourth Printing Corrections
- Third Printing Corrections

#### Fourth Printing Corrections

The following errors were corrected in the fourth printing, July 1999.

Page | Correction
48 | Updated the sources for more object-oriented programming information.
54 | Updated Figure 11 to read "Method Parameter Scope" rather than "Member ..."
61 | In third paragraph: Changed "This operator is a tertiary operator..." to "This operator is a ternary operator..."
62 | Deleted two sentences in the second paragraph: "A right shift of 1 bit ...multiplying by 2." Sentences were not replaced.
88 | In the third full paragraph, clarified the use of "default constructor." The first sentence now reads: "A constructor that takes no arguments, such as the one shown, is called a no-argument constructor."
96 | In the next-to-last paragraph, changed: "It also defines one constructor-- the default constructor..." to "It also defines one constructor--a no-argument constructor..."
97 | Added the following highlighted words: " Similarly... the compiler chooses the no-argument constructor or the default constructor..."
124 | Updated the second paragraph to read: " The no-argument constructor doesn't let the caller provide initial values for anything and the other two constructors let the caller set the initial values either for the size or for the origin and the size."

136

Updated the Stack class code. The highlighted code has been added or changed:
`public String toString() {`
`int n = items.size();`
`StringBuffer result = new StringBuffer();`
`result.append("[");`
`for (int i = 0; i < n; i++) {`
`result.append(items.elementAt(i).toString());`
`if (i < n-1) result.append(",");`
`}`
`result.append("]");`
`return result.toString();`
`}`

139 | In the first line of code on p. 139, "`Clone`" should be lower-cased. Therefore, the line of code should read: `protected Object clone() {`
139 | Clarified the explanation of the `clone` method in the first paragraph: The implementation for `Stack`'s `clone` method is relatively simple: It calls `super.clone` (`Object`'s implementation of the `clone` method) to create an instance of the correct type. The only member of `Stack`, a `Vector`, is also cloneable. Be careful: `clone` should not use new to create the clone and should not call constructors. Instead, the method should call `super.clone`, which creates an object of the correct type and allows the hierarchy of superclasses to perform the copying necessary to get a proper clone.

155

Updated the code for the `StackEnum` class:
`class StackEnum implements Enumeration {`
`int currentItem = items.size() - 1;`
`public boolean hasMoreElements() {`
`return (currentItem >= 0);`
`}`
`public Object nextElement() {`
`if (!hasMoreElements())`
`throw new NoSuchElementException();`
`else`
`return items.elementAt(currentItem--);`
`}`
`}`

156

Updated the code for the `enumerator` method:
`public Enumeration enumerator() {`
`return new Enumeration() {`
`int currentItem = items.size() - 1;`
`public boolean hasMoreElements() {`
`return (currentItem >= 0);`
`}`
`public Object nextElement() {`
`if (!hasMoreElements())`
`throw new NoSuchElementException();`
`else`
`return items.elementAt(currentItem--);`
`}`
`}`
`}`

175 | Figure 31 was updated to indicate that there is at least one class between `Container` and `Applet`.
317 | In the first full paragraph, the second sentence was corrected to read: "Let's modify the `writeList` method to specify the exceptions that it can throw instead of catching them."
331 | The code for the `SimpleThread` class was corrected so that the sleep method takes a long (rather than an int). The correct line of code is: `sleep ((``long))Math.random() * 1000));`
407 | In the first sentence under "Getting configuration information from the user," the words "the applet" were changed to "a program." The revised sentence is: "Users can specify configuration information to a program using..."
456 | In the first line of the first code snippet, "( )" was added before the semicolon. The revised line of code looks like this: `Panel p1 = new Panel();`
469 | In the first code snippet, the duplicate definition of `mouseEntered` was deleted.

469

In the second code snippet, the following lines of code were added:

`//An example of extending an adapter class.`
`public class MyClass extends MouseAdapter {`
`...`
`someObject.addMouseListener(this);`
`...`
`public void mouseClicked(MouseEvent e) {`
`...//Event handler implementation goes here...`
`}`
`}`

470 | In the first code snippet, the name of the inner class was changed from `MyClass` to `MyAdapter`. Therefore, the inner class's declaration is now: `class MyAdapter extends MouseAdapter {`
477 | Minor correction in the sentence under the "Container Event Methods" heading: "The `ContainerListener` interface... and `ContainerAdapter` contain two methods."
481 | Minor correction in the second sentence of the last paragraph: "Here is the applet's focus-event handlling code:"
487 | Deleted superfluous "the" in the last sentence on this page.
494 | In the second sentence of the first paragraph, changed "methods" to its singular ("method").
500 | Minor correction: In the first sentence under the heading "The `WindowEvent` Class," the sentence was changed from "Each mouse event method..." to "Each window event method..."
504 | In the third paragraph under the "Using Layout Managers" heading, some wording was modified to reflect the placement of the screenshots on p. 505.
505 | Minor change: In the first sentence of the last paragraph, "an" should be "and."
522 | In the first full paragraph, the second sentence was corrected to read: "Instead of implementing `LayoutManager` directly, some layout managers implement the `LayoutManager2` interface."
546 | In the second-to-last line of the code snippet, a `filter` argument was added to the `FilteredImageSource` constructor. The revised code looks like this: `ImageProducer producer = new FilteredImageSource(` `sourceImage.getSource(),` `filter);`
548 | In the seventh line on the page (in the code snippet), a `filter` argument was added, as in the above correction for page 546.

566

In the code snippet, in the `paintFrame` method, the comments were reversed. The first one now reads:
`//If we have a valid width and height for the background`
`//image, draw it.`

The second comment now reads:
`//If we have a valid width and height for the foreground`
`//image, draw it.`

568 | In the 7th line of the code snippet, a quotation mark was inserted before the T. Like this: `"T"+i+".gif")`;
570 | An additional closing bracket "`}"` was added after the code snippet. Like this: `else {` `..//same code as before...` `}`
588 | In the second sentence of the third paragraph, the word "correct" was replaced with "incorrect."
622 | In the first code snippet, the second line of code was corrected to read: `DataGramPacket packet = new DataGramPacket(buf, buf.length);`
711 | A mention of Swing was changed in the second line of the program `ScrollingSimple.java`: `java.swing.TextField;` was changed to this: `java.awt.TextField;`

929-
930

The following sentence was added to the first paragraph in the "Java Language Keywords" section:

> `true`, `false`, and `null` are not keywords but they are reserved words, so you cannot use them as names in your programs either.

`true`, `false`, and `null` were removed from Table 41: "Reserved Java Keywords." `strictfp` was added to Table 41 since `strictfp` was designated a reserved keyword in the Java 2 Platform.

[top]

#### Third Printing Corrections

The following errors were corrected in the third printing, January 1999.

Page | Correction

50

Running the countChars Method: The code shown on this page has a typo. The 'S' on `System.err` should be capitalized. To compile the program change this line:

>     system.err.println("Usage: Count filename");

to this:

> System.err.println("Usage: Count filename");

51

Data Types
Fourth sentence should read "Integers can contain only integral values..."

52

Table 1: Java's primitive data types
"Whole numbers" should be "Integers" instead. Likewise in the second sentence in the paragraph following the table.

53

Variable Names
List item "1" incorrectly refers to the Russian alphabet. It should refer instead to the Cyrillic alphabet.

54

Figure 11
Figure 11 has a typo. The label "Member Parameter Scope" should read "Method Parameter Scope".

67

Paragraph Below "By Convention" note.
The reference to the table "Operator Precedence in Java (page 932)" should actually reference page 930.

74

Branching Statements
The discussion about labeled break is incorrect. The labeled break statement breaks to the statement following the labeled statement, not to the label as stated.

75

Branching Statements
The following sentence at the end of the third paragraph is incorrect and should be removed: "The loop either continues or not depending on the results of the termination condition."

75

Branching Statements
The first paragraph about the labeled continue statement needs to be clarified. It should read "The labeled form of the `continue` statement continues at the next iteration of the labeled loop."

78

Code Sample at Top of Page
The code sample found at the top of the page has the same problem as the code on page 50. Additionally, part of the paragraph following the code sample at the top of the page reads "so `main` doesn't have do". It should read "so `main` doesn't have to".

85

Code Sample at Top of Page
The declaration for the `area` method is wrong. It should read:

>     public int area() {

That is, the `int x, int y` parameters should be removed.

96

implements Interfaces paragraph
The second sentence of the paragraph reads "applet implements and interface". It should read "applet implements an interface".

100

static Paragraph
The first sentence refers to members. It should refer to variables to make it more precise.

125

Second bullet item
The fourth line reads "confusion to other reading your code." It should read "confusion to others reading your code."

138

Being a Descendent of Object
The `hashCode` method is incorrectly listed as final. `hashCode` is not final and may be overridden by subclasses.

146

Paragraph below first code sample
The second sentence of the paragraph begins "After a specified a mount of time". It should read "After a specified amount of time".

154

Inner Classes
In the first code sample after the first paragraph in the section `public` is misspelled as `pubilc`.

156

Code Sample at the Top of Page
The `return` statement is wrong. It should read:

>     return new Enumeration () {

That is, add the parentheses after `Enumeration` as shown.

161

Managing Source and Class Files
The second paragraph in the section has an extra period '.' after the filename `Rectangle.java`.

162

Figure 28 and 29
The first line in Figures 28 and 29 should read "`package com.taranis.graphics;`" instead of "`package.com.taranis.graphics;`". Remove the extra "dot".

171

Taking Advantage of the Applet API
In the middle of the page a line reads "about how t o use the". It should read "about how to use the". There is an extra space.

229

The Window at the Bottom of the Page
The bottom two lines in the window should read:

> Sent: Hi, PC
> Received: Hi, Sun

274

Code Sample in Impurity Alert Note
The code incorrectly uses `==` when it should call the `equals` method instead:

> `// IMPURE CODE!`
> `if (System.getProperty("os.name").equals("Solaris"))`
> `doSomething();`
> `else if (System.getProperty("os.name").equals("Windows 95"))`
> `doSomethingElse();`

303

First Paragraph after Code Sample
The paragraph incorrectly refers to `getLine`. It should refer instead to `getWord`.

338

Code Sample at Top of Page
The code sample misspells `Thread` twice on the second line.

339

Code Sample in Middle of Page
The code sample misspells `Thread` once on the second line.

386

The Second `read` Method in `CheckedInputStream` class
  This line

>     cksum.update(b, 0, b.length);

should read like this

> cksum.update(b, 0, len);

389

How to Write to an ObjectOutputStream
The second line of the code sample in this section has a typo. The bold text

>     ObjectOutputStream s = new ObjectOutputStream(f);

should be changed as indicated:

> ObjectOutputStream s = new ObjectOutputStream(out);

685

Code Sample at Bottom of Page
Change this line

> `thisThread.sleep(interval);`

to

> `Thread.sleep(interval);`

The `sleep` method is a class method that puts the current thread to sleep. Calling it on a specific thread is misleading.

686 | Same correction as on page 685
687 | Same correction as on page 685

[top]

book.html | TOC | CD-ROM | References | Errata

The Java Tutorial Second Edition

Available from Amazon.com

All of the material in The Java Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.